Page({

  /**
   * 页面的初始数据
   */
  data: {
    rigthUrl: [],
    leftUrl: [],
    noramalData: [],

    leftList: [],
    rightList: [],
    leftHight: 0,
    rightHight: 0
  },

  clickImg (e) {
    wx.previewImage({
      urls: [e.currentTarget.dataset.url], 
      current: e.currentTarget.dataset.url
    })
  },
  //以本地数据为例，实际开发中数据整理以及加载更多等实现逻辑可根据实际需求进行实现   
  onLoad: function (options) {
    wx.showLoading({})
    wx.cloud.callFunction({
      name: 'getImage'
    }).then(res=>{
      const noramalData = res.result.data
      var allData = noramalData;
      //定义两个临时的变量来记录左右两栏的高度，避免频繁调用setData方法
      var leftH = this.data.leftHight;
      var rightH = this.data.rightHight;
      var leftData = [];
      var rightData = [];
      for (let i = 0; i < allData.length; i++) {
        var currentItemHeight = parseInt(Math.round(allData[i].CoverHeight * 345 / allData[i].CoverWidth));
        allData[i].CoverHeight = currentItemHeight + "rpx";//因为xml文件中直接引用的该值作为高度，所以添加对应单位
        if (leftH == rightH || leftH < rightH) {//判断左右两侧当前的累计高度，来确定item应该放置在左边还是右边
          leftData.push(allData[i]);
          leftH += currentItemHeight;
        } else {
          rightData.push(allData[i]);
          rightH += currentItemHeight;
        }
      }
      const leftUrl = leftData.map(item => {
        return item.Cover
      })
      const rigthUrl = rightData.map(item => {
        return item.Cover
      })
      //更新左右两栏的数据以及累计高度
      wx.hideLoading()
      this.setData({
        leftHight: leftH,
        rightHight: rightH,
        leftList: leftData,
        rightList: rightData,
        leftUrl,
        rigthUrl
      })
    }).catch(res=>{
      wx.showToast({
        title: '获取图片失败',
        icon: 'none'
      })
    })

  },
})